<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ tag import="java.util.*"%>
<%@ tag import="java.lang.reflect.*"%>

<%@ attribute name="attrPath" required="true" rtexprvalue="false" type="java.lang.String" description="即columnName，对应的搜索field的HQL，例如:s.brandName"%>
<%@ attribute name="attrNameKey" required="true" rtexprvalue="false" type="java.lang.String" description="搜索filed的I18N key"%>
<%@ attribute name="datatype" required="true" rtexprvalue="false" type="java.lang.String" description="搜索field的数据类型，支持:String,Integer,Short,BigDecimal,Date,Date_Begin,Date_End"%>
<%@ attribute name="operator" required="true" rtexprvalue="false" type="java.lang.String" description="搜索field的操作子:支持：EQ,LIKE,NOT,GTE,GT,LTE,LT"%>

<%@ attribute name="attrOptions" required="false" rtexprvalue="true" type="java.lang.Object" description="List列表"%>
<%@ attribute name="selectKey" required="false" type="java.lang.String" description="option value对应哪个属性"%>
<%@ attribute name="selectName" required="false" type="java.lang.String" description="option 显示值对应哪个属性"%>

<%@ attribute name="style" required="false" rtexprvalue="false" type="java.lang.String" description="搜索field input 的style属性"%>
<%@ attribute name="classes" required="false" rtexprvalue="false" type="java.lang.String" description="搜索field input 的class属性"%>
<%@ attribute name="size" required="false" rtexprvalue="false" type="java.lang.String" description="搜索field input 的size属性"%>
<%@ attribute name="labelWidth" required="false" rtexprvalue="false" type="java.lang.String" description="th的宽度"%>
<%@ attribute name="validConf" required="false" type="java.lang.String" description="客户端验证validConf属性"%>
<%@ attribute name="onenter" required="false" type="java.lang.String" description="是否回车触发搜索事件,如果等于true则触发"%>
<%@ attribute name="id" required="false" type="java.lang.String" description="input标签的id值，适用于阶段性日期的搜索，配合ui_datePicker"%>

<c:set var="attrName">COL@${attrPath}@${datatype}@${operator}</c:set>
<c:if test="${not empty attrOptions}">
	<%
		List list = (ArrayList) attrOptions;
		List results = new ArrayList();
		for (int i = 0; i < list.size(); i++) {

			Object t = list.get(i);
			try {
				String selectKeyM = "get" + selectKey;
				String selectNameM = "get" + selectName;

				Method[] ms = t.getClass().getMethods();
				Method methodK = null;
				Method methodV = null;
				for (int k = 0; k < ms.length; k++) {
					if (ms[k].getName().toLowerCase().equals(selectKeyM.toLowerCase())) {
						methodK = ms[k];
		
					}
					if (ms[k].getName().toLowerCase().equals(selectNameM.toLowerCase())) {
						methodV = ms[k];
					}
				}
				Object obj = methodK.invoke(t, null);
				Object obj2 = methodV.invoke(t, null);
				Hashtable h = new Hashtable();
				h.put("key", obj);
				h.put("value", obj2);
				results.add(h);

			} catch (Exception e) {
				out.println(e.toString());
			}
			request.setAttribute("ProbizListProc", results);

		}
	%>
</c:if>
<tr>
	<th width="${labelWidth}"><label for="${attrName}"><fmt:message key="${attrNameKey}"/><fmt:message key="common.message.colon"/></label></th>
	<td>
		<select name="${attrName}" id="${attrName}" 
				<c:if test="${not empty style}">style="${style}"</c:if> 
				<c:if test="${not empty classes}">class="${classes}"</c:if> 
				<c:if test="${not empty validConf}"> validConf="${validConf}" onblur="validateEventHandler();"</c:if> 
				<c:if test='${onenter == "true"}'>onkeyup="doSearchHandlerWhenEnter(event)"</c:if>>
				
			<option value=""><fmt:message key="common.message.all"></fmt:message></option>
			<c:forEach var="item" items="${ProbizListProc}">
				<option value="${item.key}" ${(sc==null?(item.key==requestScope[attrName]):(item.key==sc.param[attrName]))?'selected':''}>
			      ${item.value}
				</option>
			</c:forEach>
		</select>
	</td>
</tr>
